package com.hkfn.rfb.rfb.fragment;

import android.app.Dialog;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.ValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.hkfn.rfb.R;
import com.hkfn.rfb.common.activity.BaseActivity;
import com.hkfn.rfb.common.adapter.BaseRecyclerAdapter;
import com.hkfn.rfb.common.bean.BannerModel;
import com.hkfn.rfb.common.bean.chart.ChartModel;
import com.hkfn.rfb.common.bean.chart.LineModel;
import com.hkfn.rfb.common.fragment.BaseFragment;
import com.hkfn.rfb.common.utils.DialogUtils;
import com.hkfn.rfb.databinding.FRfbTrendSummaryBinding;
import com.hkfn.rfb.rfb.bean.RfbParamManager;
import com.hkfn.rfb.rfb.tableview.TableViewAdapter;
import com.hkfn.rfb.rfb.tableview.TableViewListener;
import com.hkfn.rfb.rfb.tableview.model.Cell;
import com.hkfn.rfb.rfb.tableview.model.ColumnHeader;
import com.hkfn.rfb.rfb.tableview.model.RowHeader;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 分析汇总
 */
public class RfbTrendSummaryFragment extends BaseFragment {

    private BaseActivity activity;

    private Bundle bundle;

    private FRfbTrendSummaryBinding fRfbTrendSummaryBinding;

    private int currentPage = -1;// 当前选中页面

    private boolean isShowNormalData = true;// 显示正常数据或循环数据

    private TableViewAdapter tableViewAdapter;

    private Dialog chooseProjectDialog;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        activity = getMyActivity();
        bundle = getArguments();
        fRfbTrendSummaryBinding = FRfbTrendSummaryBinding.inflate(inflater, container, false);
        initView();
        return fRfbTrendSummaryBinding.getRoot();
    }

    private void initView() {
        initHeadTabs();

        initHeadChooseView();

        initLineChart(fRfbTrendSummaryBinding.lcTrendSummary);

        initializeTableView();

        clickHeadTabAction(0);
    }

    private void initHeadTabs() {
        fRfbTrendSummaryBinding.tvTabBattery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickHeadTabAction(0);
            }
        });
        fRfbTrendSummaryBinding.tvTabTemperature.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickHeadTabAction(1);
            }
        });
        fRfbTrendSummaryBinding.tvTabGas.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickHeadTabAction(2);
            }
        });

        fRfbTrendSummaryBinding.llChangeChart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                if (fRfbTrendSummaryBinding.lcTrendSummary.getVisibility() == View.GONE){
//                    fRfbTrendSummaryBinding.lcTrendSummary.setVisibility(View.VISIBLE);
//                    fRfbTrendSummaryBinding.tableView.setVisibility(View.GONE);
//                    fRfbTrendSummaryBinding.tvChangeChart.setText("切换表格");
//                }else {
//                    fRfbTrendSummaryBinding.lcTrendSummary.setVisibility(View.GONE);
//                    fRfbTrendSummaryBinding.tableView.setVisibility(View.VISIBLE);
//                    fRfbTrendSummaryBinding.tvChangeChart.setText("切换图表");
//                }
            }
        });
    }

    private void clickHeadTabAction(int clickIndex){
        if (clickIndex != currentPage){
            // 将当前已选中tabs设为未选中状态
            switch (currentPage){
                case 0:
                    fRfbTrendSummaryBinding.tvTabBattery.setBackground(activity.getResources().getDrawable(R.drawable.shape_rfb_head_tab_border_frame));
                    break;
                case 1:
                    fRfbTrendSummaryBinding.tvTabTemperature.setBackground(activity.getResources().getDrawable(R.drawable.shape_rfb_head_tab_border_frame));
                    break;
                case 2:
                    fRfbTrendSummaryBinding.tvTabGas.setBackground(activity.getResources().getDrawable(R.drawable.shape_rfb_head_tab_border_frame));
                    break;
            }
            currentPage = clickIndex;
            // 将当前点击tabs设为选中状态
            switch (currentPage){
                case 0:
                    fRfbTrendSummaryBinding.tvTabBattery.setBackground(activity.getResources().getDrawable(R.drawable.shape_rfb_head_tab_select_frame));
                    fRfbTrendSummaryBinding.llChangeData.setVisibility(View.VISIBLE);
                    break;
                case 1:
                    fRfbTrendSummaryBinding.tvTabTemperature.setBackground(activity.getResources().getDrawable(R.drawable.shape_rfb_head_tab_select_frame));
                    fRfbTrendSummaryBinding.llChangeData.setVisibility(View.INVISIBLE);
                    break;
                case 2:
                    fRfbTrendSummaryBinding.tvTabGas.setBackground(activity.getResources().getDrawable(R.drawable.shape_rfb_head_tab_select_frame));
                    fRfbTrendSummaryBinding.llChangeData.setVisibility(View.INVISIBLE);
                    break;
            }
            refreshFormAndLineData();
        }
    }

    private void initHeadChooseView() {
        fRfbTrendSummaryBinding.llSelectProject.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogUtils.closeDialog(chooseProjectDialog);
                List<BannerModel> list = new ArrayList<>();
                BannerModel bannerModel = new BannerModel();
                bannerModel.setTitle("项目1");
                list.add(bannerModel);
                BannerModel bannerModel1 = new BannerModel();
                bannerModel1.setTitle("项目2");
                list.add(bannerModel1);
                BannerModel bannerModel2 = new BannerModel();
                bannerModel2.setTitle("项目3");
                list.add(bannerModel2);
                BannerModel bannerModel3 = new BannerModel();
                bannerModel3.setTitle("项目4");
                list.add(bannerModel3);
                BannerModel bannerModel4 = new BannerModel();
                bannerModel4.setTitle("项目5");
                list.add(bannerModel4);
                chooseProjectDialog = DialogUtils.createChooseListDialog(activity, list, "选择项目", -1, new BaseRecyclerAdapter.OnItemClickListener() {
                    @Override
                    public void onItemClick(View v, int position, Object data) {
                        DialogUtils.closeDialog(chooseProjectDialog);
                        fRfbTrendSummaryBinding.tvSelectProject.setText(((BannerModel)data).getTitle());
                        refreshFormAndLineData();
                    }
                });
                DialogUtils.showDialog(chooseProjectDialog);
            }
        });

        fRfbTrendSummaryBinding.llChangeData.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isShowNormalData = !isShowNormalData;
                refreshFormAndLineData();
            }
        });
    }

    /**
     * 初始化折线图
     */
    private void initLineChart(LineChart lineChart) {
        // no description text
        lineChart.getDescription().setEnabled(false);

        // enable touch gestures
        lineChart.setTouchEnabled(true);

        // enable scaling and dragging
        lineChart.setDragEnabled(true);
        lineChart.setScaleEnabled(true);

        // if disabled, scaling can be done on x- and y-axis separately
        lineChart.setPinchZoom(true);

        lineChart.setDrawGridBackground(false);
        lineChart.setMaxHighlightDistance(300);

        lineChart.getAxisRight().setEnabled(false);

        Legend legend = lineChart.getLegend();
        legend.setEnabled(true);
        legend.setTextColor(activity.getResources().getColor(R.color.white));
        legend.setTextSize(18);
        legend.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        legend.setWordWrapEnabled(true);
        legend.setXEntrySpace(30);
        legend.setYEntrySpace(10);


        lineChart.animateXY(0, 800);
        lineChart.setScaleYEnabled(false);


        XAxis x = lineChart.getXAxis();
        x.setTextColor(activity.getResources().getColor(R.color.white));
        x.setEnabled(true);
        x.setDrawGridLines(false);
        x.setPosition(XAxis.XAxisPosition.BOTTOM);
        x.setAxisLineColor(Color.WHITE);
        x.setGranularityEnabled(false);
        x.setGranularity(1);
        x.setValueFormatter(new ValueFormatter() {
            @Override
            public String getFormattedValue(float value) {
                return (int)value+"";
            }

        });

        YAxis y = lineChart.getAxisLeft();
        Typeface tfLight = Typeface.DEFAULT;
        y.setTypeface(tfLight);
        y.setTextColor(activity.getResources().getColor(R.color.white));
        y.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
        y.setDrawGridLines(false);
        y.setAxisLineColor(Color.WHITE);
        y.setGranularityEnabled(false);
        y.setGranularity(1);
    }

    private void initializeTableView() {
        // Create TableView View model class  to group view models of TableView
        //TableViewModel tableViewModel = new TableViewModel();

        // Create TableView Adapter
        tableViewAdapter = new TableViewAdapter();

        fRfbTrendSummaryBinding.tableView.setAdapter(tableViewAdapter);
        fRfbTrendSummaryBinding.tableView.setTableViewListener(new TableViewListener(fRfbTrendSummaryBinding.tableView));
        fRfbTrendSummaryBinding.tableView.setRowHeaderWidth(activity.getResources().getDimensionPixelSize(R.dimen.row_header_width));
        // Create an instance of a Filter and pass the TableView.
        //mTableFilter = new Filter(mTableView);

        // Load the dummy data to the TableView
//        tableViewAdapter.setAllItems(tableViewModel.getColumnHeaderList(), tableViewModel
//                .getRowHeaderList(), tableViewModel.getCellList());



        //mTableView.setHasFixedWidth(true);

        /*for (int i = 0; i < mTableViewModel.getCellList().size(); i++) {
            mTableView.setColumnWidth(i, 200);
        }*)

        //mTableView.setColumnWidth(0, -2);
        //mTableView.setColumnWidth(1, -2);

        /*mTableView.setColumnWidth(2, 200);
        mTableView.setColumnWidth(3, 300);
        mTableView.setColumnWidth(4, 400);
        mTableView.setColumnWidth(5, 500);*/

    }

    /**
     * 刷新列表和折线图数据
     */
    private void refreshFormAndLineData() {
        // 设置表格数据
        setDataFormData();

        setLineChartData(fRfbTrendSummaryBinding.lcTrendSummary);
    }

    private void setDataFormData() {
        fRfbTrendSummaryBinding.tableView.scrollToColumnPosition(0);
        fRfbTrendSummaryBinding.tableView.scrollToRowPosition(0);
        List<ColumnHeader> randomColumnHeaderList = getRandomColumnHeaderList();
        List<RowHeader> simpleRowHeaderList = getSimpleRowHeaderList();
        tableViewAdapter.setAllItems(randomColumnHeaderList, simpleRowHeaderList,
                getCellListForSortingTest(randomColumnHeaderList, simpleRowHeaderList));
    }

    @NonNull
    private List<RowHeader> getSimpleRowHeaderList() {
        List<RowHeader> list = new ArrayList<>();
        int length = 20;
        if (currentPage == 0 && !isShowNormalData){
            length = 36;
        }
        for (int i = 0; i < length; i++) {
            RowHeader header = new RowHeader(String.valueOf(i), ""+(i+1));
            list.add(header);
        }
        return list;
    }

    /**
     * This is a dummy model list test some cases.
     */
    @NonNull
    private List<ColumnHeader> getRandomColumnHeaderList() {
        tableViewAdapter.setNeedBigWidth(false);
        if (null != tableViewAdapter.getTv_corner_name()) {
            tableViewAdapter.getTv_corner_name().setText("时间");
        }
        List<ColumnHeader> list = new ArrayList<>();
        List<String> dataList = new ArrayList<>();
        switch (currentPage){
            case 0:
                String[] dataStrs;
                if (isShowNormalData) {
                    dataStrs = new String[]{"电堆电流(A)", "电堆功率(kW)", "开路电压(V)", "SOC(%)", "单电池电压1(V)", "单电池电压10(V)", "单电池电压20(V)", "单电池电压30(V)", "单电池电压40(V)", "单电池电压50(V)"};
                }else {
                    dataStrs = new String[]{"能量效率(%)", "库仑效率(%)", "电压效率(%)", "充电容量(Ah)", "放电容量(Ah)", "充电能量(kWh)","放电能量(kWh)"};
                    tableViewAdapter.setNeedBigWidth(true);
                    if (null != tableViewAdapter.getTv_corner_name()) {
                        tableViewAdapter.getTv_corner_name().setText("循环次数");
                    }
                }
                for (int i = 0; i < dataStrs.length; i++) {
                    dataList.add(dataStrs[i]);
                }
                break;
            case 1:
                for (int i = 0; i < RfbParamManager.temperatureTrendParamManager.size(); i++) {
                    dataList.add(RfbParamManager.temperatureTrendParamManager.get(i).getParamNameAndUnit());
                }
                break;
            default:
                for (int i = 0; i < RfbParamManager.gasParamManager.size(); i++) {
                    dataList.add(RfbParamManager.gasParamManager.get(i).getParamNameAndUnit());
                }
                break;
        }

        for (int i = 0; i < dataList.size(); i++) {
            ColumnHeader header = new ColumnHeader(String.valueOf(i),  dataList.get(i));
            list.add(header);
        }
        return list;
    }

    /**
     * This is a dummy model list test some cases.
     */
    @NonNull
    private List<List<Cell>> getCellListForSortingTest(List<ColumnHeader> columnHeaderItems, List<RowHeader> rowHeaderItems) {
        List<List<Cell>> list = new ArrayList<>();
        for (int i = 0; i < rowHeaderItems.size(); i++) {
            List<Cell> cellList = new ArrayList<>();
            double press1 = 0;
            double press2 = 0;
            double airPress1 = 0;
            double airPress2 = 0;
            for (int j = 0; j < columnHeaderItems.size(); j++) {
                Random random = new Random();
                // Create dummy id.
                String id = j + "-" + i;
                Cell cell;
                if (currentPage == 1){
                    String valueStr = RfbParamManager.temperatureTrendParamManager.get(j).getParamRandomValue(i);
                    if (j == 0){
                        press1 = Double.parseDouble(valueStr);
                    }else if (j == 5){
                        press2 = Double.parseDouble(valueStr);
                    }else if (j == 10){
                        valueStr = String.format("%.3f", press1 - press2);
                    }
                    cell = new Cell(id, valueStr);
                } else if (currentPage == 2) {
                    String valueStr = RfbParamManager.gasParamManager.get(j).getParamRandomValue(i);
                    if (j == 0){
                        airPress1 = Double.parseDouble(valueStr);
                    }else if (j == 1){
                        airPress2 = Double.parseDouble(valueStr);
                    }else if (j == 2){
                        valueStr = String.format("%.3f", airPress1 - airPress2);
                    }
                    cell = new Cell(id, valueStr);
                }else if (currentPage == 0 && !isShowNormalData){
                    cell = new Cell(id, xunHuanData[i][j]);
                }else if (currentPage == 0){
                    cell = new Cell(id, normalData[i][j]);
                }else {
                    cell = new Cell(id, "0");
                }
                cellList.add(cell);
            }
            list.add(cellList);
        }

        return list;
    }

    private String[][] normalData = {
            {"1082.667", "17.821", "1.389", "17.341", "1.480", "1.482", "1.483", "1.482", "1.478", "1.481"},
            {"812.000", "55.216", "1.403", "20.389", "1.494", "1.493", "1.495", "1.494", "1.489", "1.486"},
            {"812.000", "55.845", "1.416", "23.744", "1.507", "1.501", "1.503", "1.505", "1.498", "1.499"},
            {"812.000", "57.392", "1.432", "20.389", "1.523", "1.521", "1.511", "1.519", "1.516", "1.515"},
            {"813.164", "57.767", "1.442", "23.744", "1.533", "1.530", "1.529", "1.527", "1.527", "1.525"},
            {"812.000", "57.924", "1.453", "27.310", "1.544", "1.539", "1.541", "1.538", "1.537", "1.533"},
            {"812.000", "58.273", "1.461", "31.251", "1.552", "1.546", "1.551", "1.551", "1.544", "1.542"},
            {"812.000", "58.602", "1.469", "35.497", "1.560", "1.557", "1.560", "1.562", "1.553", "1.553"},
            {"813.164", "59.003", "1.478", "39.700", "1.569", "1.565", "1.568", "1.670", "1.565", "1.561"},
            {"812.000", "59.308", "1.486", "43.650", "1.577", "1.574", "1.575", "1.578", "1.577", "1.571"},
            {"812.000", "59.645", "1.494", "47.472", "1.585", "1.582", "1.586", "1.584", "1.583", "1.577"},
            {"813.164", "60.121", "1.502", "51.294", "1.593", "1.590", "1.596", "1.602", "1.594", "1.580"},
            {"812.000", "60.466", "1.510", "55.116", "1.601", "1.598", "1.603", "1.609", "1.602", "1.587"},
            {"812.000", "61.310", "1.519", "58.938", "1.610", "1.605", "1.609", "1.613", "1.612", "1.609"},
            {"812.000", "61.359", "1.527", "62.761", "1.618", "1.612", "1.619", "1.620", "1.620", "1.613"},
            {"812.000", "61.850", "1.536", "70.405", "1.627", "1.621", "1.625", "1.629", "1.628", "1.621"},
            {"813.164", "62.443", "1.544", "74.227", "1.635", "1.631", "1.633", "1.634", "1.634", "1.629"},
            {"812.000", "62.869", "1.549", "78.049", "1.640", "1.639", "1.641", "1.641", "1.643", "1.638"},
            {"813.164", "63.528", "1.554", "81.871", "1.645", "1.641", "1.644", "1.650", "1.651", "1.649"},
            {"813.164", "64.411", "1.561", "84.240", "1.652", "1.650", "1.653", "1.659", "1.658", "1.654"}
    };

    private String[][] xunHuanData = {
            {"38.976", "42.991", "90.660", "1800.048", "773.864", "102.149", "39.814"},
            {"80.385", "94.519", "85.046", "836.800", "790.936", "50.633", "40.701"},
            {"77.342", "91.062", "84.933", "866.712", "789.248", "52.451", "40.566"},
            {"80.799", "95.055", "85.002", "819.304", "778.792", "49.509", "40.003"},
            {"80.947", "94.965", "85.239", "806.048", "765.464", "48.545", "39.296"},
            {"81.088", "94.900", "85.446", "791.656", "751.280", "47.543", "38.551"},
            {"81.131", "94.810", "85.572", "777.328", "736.984", "46.582", "37.792"},
            {"81.166", "94.811", "85.607", "762.752", "723.176", "45.663", "37.063"},
            {"76.478", "89.916", "85.055", "803.224", "722.224", "48.405", "37.019"},
            {"81.087", "95.454", "84.949", "748.472", "714.448", "45.136", "36.599"},
            {"81.080", "95.200", "85.168", "740.864", "705.304", "44.549", "36.120"},
            {"81.181", "95.124", "85.343", "730.960", "695.320", "43.844", "35.593"},
            {"81.195", "94.989", "85.479", "721.096", "684.960", "43.159", "35.043"},
            {"81.173", "94.822", "85.605", "711.128", "674.304", "42.488", "34.489"},
            {"81.302", "94.855", "85.712", "700.488", "664.448", "41.789", "33.975"},
            {"81.215", "94.678", "85.779", "690.616", "653.864", "41.145", "33.415"},
            {"74.379", "87.908", "84.610", "766.208", "673.560", "46.316", "34.450"},
            {"80.903", "95.836", "84.418", "698.288", "669.208", "42.284", "34.209"},
            {"81.053", "95.716", "84.680", "694.936", "665.168", "41.959", "34.009"},
            {"80.999", "95.366", "84.934", "688.896", "656.976", "41.463", "33.585"},
            {"81.042", "95.211", "85.117", "681.128", "648.512", "40.905", "33.150"},
            {"75.909", "89.741", "84.588", "731.656", "656.592", "44.192", "33.546"},
            {"81.090", "95.941", "84.521", "681.008", "653.368", "41.147", "33.366"},
            {"80.914", "95.420", "84.798", "677.560", "646.528", "40.810", "33.021"},
            {"81.227", "95.586", "84.978", "670.048", "640.472", "40.255", "32.698"},
            {"81.077", "95.217", "85.150", "665.160", "633.344", "39.875", "32.330"},
            {"81.354", "95.387", "85.289", "657.392", "627.064", "39.329", "31.996"},
            {"80.974", "94.874", "85.350", "651.528", "618.128", "38.943", "31.534"},
            {"75.134", "87.712", "85.660", "642.000", "563.112", "38.416", "28.864"},
            {"81.050", "96.164", "84.284", "639.776", "615.232", "38.675", "31.346"},
            {"81.035", "95.944", "84.461", "639.896", "613.944", "38.578", "31.262"},
            {"80.791", "95.357", "84.724", "638.072", "608.448", "38.361", "30.992"},
            {"80.898", "95.275", "84.910", "631.312", "601.480", "37.870", "30.636"},
            {"81.082", "95.305", "85.076", "625.408", "596.048", "37.440", "30.357"},
            {"79.573", "93.504", "85.102", "633.704", "592.536", "37.923", "30.177"},
            {"80.825", "95.218", "84.884", "615.616", "586.176", "36.918", "29.839"}
    };

    private String[][] temperatureData = {};

    private String[][] gasData = {};


    private void setLineChartData(LineChart lineChart){
        ChartModel chartModel = getCurrentChartData();
//        switch (currentPage){
//            case 0:
//                chartModel = (ChartModel) getBatteryData(false);
//                break;
//            case 1:
//                chartModel = (ChartModel) getTemperatureData(false);
//                break;
//            case 2:
//                chartModel = (ChartModel) getGasData(false);
//                break;
//            default:
//                return;
//        }

        XAxis x = lineChart.getXAxis();
        x.setLabelCount(chartModel.getXAxisValues().size());
        //创建一个数据集
        ArrayList<ILineDataSet> dataSets = new ArrayList<>();
        List<LineModel> lineModels = chartModel.getLineModels();
        int[] colors = activity.getResources().getIntArray(R.array.chart_line_colors);
        for (int i = 0; i < lineModels.size(); i++) {
            ArrayList<Entry> entries = new ArrayList<>();
            for (int j = 0; j < lineModels.get(i).getYAxisValues().size(); j++) {
                entries.add(new Entry(j, lineModels.get(i).getYAxisValues().get(j)));
            }
            int color = colors[i % 16];
            // create a dataset and give it a type
            LineDataSet lineDataSet = new LineDataSet(entries, lineModels.get(i).getLineTitle());
            lineDataSet.setDrawFilled(true);
            lineDataSet.setDrawCircles(false);
            lineDataSet.setDrawValues(false);
            lineDataSet.setCircleHoleColor(color);
            lineDataSet.setLineWidth(2f);
            lineDataSet.setCircleRadius(2f);
            lineDataSet.setCircleColor(color);
            lineDataSet.setColor(color);
            lineDataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
            lineDataSet.setFillDrawable(activity.getResources().getDrawable(R.drawable.shape_chart_line_bg));

            dataSets.add(lineDataSet);
        }

        LineData lineData = new LineData(dataSets);
        //设置数据
        lineChart.setData(lineData);
        lineChart.invalidate();
    }


    private ChartModel getCurrentChartData(){
        String[] dateList = new String[]{"2025/5/10", "2025/5/11", "2025/5/12", "2025/5/13", "2025/5/14", "2025/5/15", "2025/5/16"};

        ChartModel chartModel = new ChartModel();
        List<Float> xAxisValues = new ArrayList<>();
        for (int i = 0; i < 200; i++) {
            xAxisValues.add((float) (i+1));
        }
        chartModel.setXAxisValues(xAxisValues);

        List<LineModel> lineModels = new ArrayList<>();
        for (int i = 0; i < dateList.length; i++) {
            LineModel lineModel = new LineModel();
            lineModel.setLineTitle(dateList[i]);
            List<Float> yAxisValues = new ArrayList<>();
            for (int j = 0; j < 200; j++) {
                Random random = new Random();
                yAxisValues.add(random.nextFloat() * 100);
            }
            lineModel.setYAxisValues(yAxisValues);
            lineModels.add(lineModel);
        }
        chartModel.setLineModels(lineModels);
        return chartModel;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        DialogUtils.closeDialog(chooseProjectDialog);
    }
}
